const gulp = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const connect = require("gulp-connect");
const sourcemaps = require("gulp-sourcemaps");

gulp.task("html",done=>{
    gulp.src("src/*.html").pipe(gulp.dest("dist")).pipe(connect.reload());
    done();
})
gulp.task("img",done=>{
    gulp.src("src/img/**").pipe(gulp.dest("dist/img"))
    done();
})
gulp.task("sass", (done) => {
    gulp
      .src("src/sass/*.scss")
      .pipe(sourcemaps.init()) //初始化
      /* .pipe(sass({
          outputStyle: "compressed"
        })) //全压缩 */
      .pipe(sass())
      .pipe(sourcemaps.write("./")) //路径
      .pipe(gulp.dest("dist/css"))
      .pipe(connect.reload());
    done();
  });
gulp.task("css",done=>{
    gulp.src("src/css/**").pipe(gulp.dest("dist/css"))
    done();
});
gulp.task("js",done=>{
    gulp.src("src/js/**").pipe(gulp.dest("dist/js"))
    done();
});
gulp.task("watch",done=>{
    gulp.watch("src/*.html",gulp.series("html"));
    gulp.watch("src/img/**",gulp.series("img"));
    gulp.watch("src/css/**",gulp.series("css"));
    gulp.watch("src/js/**",gulp.series("js"));
    gulp.watch("src/sass/*.scss", gulp.series("sass"));

    done();
})

gulp.task("server",done=>{
    connect.server({
        root:"dist",
        livereload:true,
    });
    done();
})

gulp.task("default",gulp.series("server","watch"))